
jQuery(document).ready(function() {
	"use strict";

	// Call all ready functions
	appinocks_navbarFixed(),
	appinocks_navScrollSpy(),
	appinocks_counterUp(),
	appinocks_magnificPopupVideo(),
	appinocks_owl_carousel(),
	appinocks_pricingTab(),
	appinocks_copyrightDynamicYear(),
	
	appinocks_contactForm(),
	appinocks_faqForm(),
	
	appinocks_loginForm(),
	appinocks_show_psd(),
	appinocks_portForm1(),
	appinocks_privacy_plokicy(),
	appinocks_regForm(),
	appinocks_userEdit(),
		
	appinocks_preloader(),
	appinocks_scrollIt(),
	new WOW().init();
});

/*  ---------------------------------------------------
    1.导航条固定
    --------------------------------------------------- */
function appinocks_navbarFixed() {
	"use-strict";

	// Variables
	var scrollTop = jQuery(window).scrollTop(),
		navbarMenu = jQuery(".header"),
		navbarLink = jQuery('.navbar-nav>li>a'),
		scrollTopBtn = jQuery('.scroll-top-btn'),
		downloadBtn = jQuery('#downloadBtn'),
		downScroll = jQuery('.down-scroll'),
		navbarHamburgerBtn = jQuery('.navbar-hamburger');

	// Window On Scroll Add Class Shrink
	jQuery(window).on("scroll", function() {
		let scrollTop = jQuery(this).scrollTop();
		if (scrollTop > 80) {
			navbarMenu.addClass("header-shrink");
			scrollTopBtn.addClass('active');
			
		} else {
			navbarMenu.removeClass("header-shrink");
			scrollTopBtn.removeClass('active');
		}
	});

	if (scrollTop > 100) {
		navbarMenu.addClass("header-shrink");
		scrollTopBtn.addClass('active');
	} else {
		navbarMenu.removeClass("header-shrink");
		scrollTopBtn.removeClass('active');
	}

	navbarLink.on('click', function() {
		jQuery('.navbar-collapse').collapse('hide');
		navbarHamburgerBtn.toggleClass('active');
	});
}

/*  ---------------------------------------------------
    2.Navbar Scroll Spy
    --------------------------------------------------- */
function appinocks_navScrollSpy() {
	"use-strict";

	// Scroll Spy
	jQuery('body').scrollspy({
		target: '#fixedNavbar',
		offset: 95
	});
}
function appinocks_navScrollSpy1() {
	"use-strict";

	// Scroll Spy
	jQuery('body').scrollspy({
		target: '#fixedNavbar',
		offset: 95
	});
}

/*  ---------------------------------------------------
    3.Counters
    --------------------------------------------------- */
function appinocks_counterUp() {
	"use-strict";

	jQuery('.counter').counterUp({
		delay: 15,
		time: 2000
	});
}

/*  -----------------------------------------------------
    4.Owl Carousel
    ----------------------------------------------------- */
function appinocks_owl_carousel() {
	"use-strict";

	// Variables 
	var testimonialSlider = jQuery('.testimonial-slider'),
		screenshotsSlider = jQuery('.screenshots-slider');

	// Partners Slider
	screenshotsSlider.owlCarousel({
		loop: true,
		margin: 30,
		nav: true,
		dots: false,
		center: true,
		stagePadding: 0,
		smartSpeed: 1000,
		animateOut: 'fadeOut',
		autoplay: true,
		autoplayTimeout: 3000,
		autoplayHoverPause: true,
		navText: ["<span class='fa fa-angle-left'></span>", "<span class='fa fa-angle-right'></span>"],
		responsive: {
			0: {
				items: 2,
				center: false
			},
			600: {
				items: 3
			},
			768: {
				items: 3
			},
			1000: {
				items: 4
			}
		}
	});

	// Testimonial Slider
	testimonialSlider.owlCarousel({
		loop: false,
		margin: 30,
		nav: false,
		dots: true,
		stagePadding: 0,
		smartSpeed: 1000,
		animateOut: 'fadeOut',
		autoplay: true,
		autoplayTimeout: 3000,
		autoplayHoverPause: true,
		responsive: {
			0: {
				items: 1
			},
			768: {
				items: 1
			},
			992: {
				items: 2
			}
		}
	});
}

/*  -----------------------------------------------------
    5.Video
    ----------------------------------------------------- */
function appinocks_magnificPopupVideo() {
	"use-strict";

	// Variables
	var videoPopupItem = jQuery('.popup-youtube, .popup-vimeo, .popup-gmaps');

	videoPopupItem.magnificPopup({
		disableOn: 700,
		type: 'iframe',
		mainClass: 'mfp-fade',
		removalDelay: 160,
		preloader: false,
		fixedContentPos: false
	});
}

/*  -----------------------------------------------------
    6.价格标签
    ----------------------------------------------------- */
function appinocks_pricingTab() {
	"use-scrict";

	// Variables
	var pricingTabLink = jQuery('.price-toggle-wrap > a'),
		pricingTabContent = jQuery('.pricing-tab-content');

	pricingTabLink.on("click", function() {
		pricingTabLink.removeClass('active');
		jQuery(this).addClass('active');
		pricingTabContent.removeClass('active');
		pricingTabContent.eq(jQuery(this).index()).addClass("active animated fadeInUp");
	});
}

/*  -----------------------------------------------------
    7. 著作权时间（年）
    ----------------------------------------------------- */
function appinocks_copyrightDynamicYear() {
	"use-strict";

	// Variables
	var fullYearCopyright = jQuery('#fullYearCopyright'),
		getFullYearDate = new Date().getFullYear();

	fullYearCopyright.text(getFullYearDate);
}

/*  -----------------------------------------------------
    8.0 联系表单
    ----------------------------------------------------- */
function appinocks_contactForm() {
	"use-strict";

	jQuery("#contactBtn").on("click", function(event) {
		event.preventDefault();

		// 电子邮件验证函数
		function validateEmail(email) {
			var regexp =
				/^(([^<>()\[\]\\.,;:\s@"]+(\.[^<>()\[\]\\.,;:\s@"]+)*)|(".+"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
			return regexp.test(String(email).toLowerCase());
		}

		// 获取联系表单输入值
		var name = jQuery("#contactName").val().trim();
		var email = jQuery("#contactEmail").val().trim();
		var phone = jQuery("#contactPhone").val().trim();
		var subject = jQuery("#contactSubject").val().trim();
		var message = jQuery("#contactMessage").val().trim();

		// 检查邮件字段
		if (email !== '') {
			var validateEmail	= validateEmail(email);
			if (validateEmail===false) {
				jQuery('div.email-invalid').slideDown(500).delay(2000).slideUp(500);
				return;
			}
		}
		// 检查空字段
		if (name === '') {
			jQuery('div.empty-name').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查空字段
		if (subject === '') {
			jQuery('div.empty-form').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查空字段
		if (message === '') {
			jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 信息得到验证，就会发送表单。FIXME
		/*var url = "/login_do";
		var urlData = {login_name: name, password: pwd};
		
        jQuery.post(url, urlData,
			function (data) {
	            if (data.status) {
	            	// 登入成功
	                window.location.replace(data.url);
	                 
	             } else {
	            	 // 登入失败
	            	 jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
	             }
	        }, "json"
		);*/
		jQuery('div.empty-ok').slideDown(500).delay(2000).slideUp(500);
		jQuery("#contactName").val("");
		jQuery("#contactEmail").val("");
		jQuery("#contactPhone").val("");
		jQuery("#contactSubject").val("");
		jQuery("#contactMessage").val("");
	});
}

/*  -----------------------------------------------------
    8.0.1 问题联系表单
    ----------------------------------------------------- */
function appinocks_faqForm() {
	"use-strict";

	jQuery("#faqFormBtn").on("click", function(event) {
		event.preventDefault();

		// 获取联系表单输入值
		var faqFormName = jQuery("#faqFormName").val().trim();
		var faqFormProblem = jQuery("#faqFormProblem").val().trim();
		var faqFormMessage = jQuery("#faqFormMessage").val().trim();

		// 检查空字段
		if (faqFormName === '') {
			jQuery('div.empty-faq-name').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查空字段
		if (faqFormProblem === '') {
			jQuery('div.empty-faq-form').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查空字段
		if (faqFormMessage === '') {
			jQuery('div.empty-faq-msg').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 信息得到验证，就会发送表单。FIXME
		/*var url = "/login_do";
		var urlData = {login_name: name, password: pwd};
		
        jQuery.post(url, urlData,
			function (data) {
	            if (data.status) {
	            	// 登入成功
	                window.location.replace(data.url);
	                 
	             } else {
	            	 // 登入失败
	            	 jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
	             }
	        }, "json"
		);*/
		jQuery('div.empty-faq-ok').slideDown(500).delay(2000).slideUp(500);
		jQuery("#faqFormName").val("");
		jQuery("#faqFormProblem").val("");
		jQuery("#faqFormMessage").val("");
	});
}

/*	-----------------------------------------------------
	8.1 登入表单
	----------------------------------------------------- */
function appinocks_loginForm() {
	"use-strict";

	jQuery("#loginBtn").on("click", function(event) {
		event.preventDefault();

		// 获取联系表单输入值
		var name = jQuery("#login_name").val().trim(),
			pwd = jQuery("#login_pwd").val().trim();

		// 检查空字段
		if (name === '') {
			jQuery('div.empty-name').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查空字段
		if (pwd === '') {
			jQuery('div.empty-pwd').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 信息得到验证 - 发送登入表单
		var url = "/login_do";
		var urlData = {login_name: name, password: pwd};
		
        jQuery.post(url, urlData,
			function (data) {
	            if (data.status) {
	            	// 登入成功
	                window.location.replace(data.url);
	                 
	             } else {
	            	 // 登入失败
	            	 jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
	             }
	        }, "json"
		);
	});
}

/*显示或隐藏密码*/
function appinocks_show_psd() {
	"use-strict";

	//隐藏text block，显示password block
	jQuery("#show_psd").on("click", function(event) {
		event.preventDefault();
		let type = jQuery("#login_pwd").attr('type');
		if(type === "password"){
			jQuery("#login_pwd").attr("type","text");
			jQuery("#login_pwd_ch").attr("type","text");
			jQuery("#show_psd").attr("class","fa fa-eye-slash fa-lg");
			
		}else{
			jQuery("#login_pwd").attr("type","password");
			jQuery("#login_pwd_ch").attr("type","password");
			jQuery("#show_psd").attr("class","fa fa-eye fa-lg");
		}
	});
}

/*	-----------------------------------------------------
	8.2 报告表单
	----------------------------------------------------- */
function appinocks_portForm1() {
	"use-strict";

	jQuery("#postBtn").on("click", function(event) {
		event.preventDefault();

		// 发送验证表单
		var url = "/report_check";
		
        jQuery.post(url, null,
			function (data) {
	            if (data.status) { // 登入
	            	if (data.err == 0) {
		                window.location.replace(data.url);
	            		
	            	} else if (data.err == 1) {
		            	 // 不具备权限
		            	 jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
	            	}
	                 
	             } else {// 未登入
		                window.location.replace(data.url);
	             }
	        }, "json"
		);
	});
}
/*	-----------------------------------------------------
	8.3 注册表单
	----------------------------------------------------- */
function appinocks_regForm() {
	"use-strict";

	jQuery("#regBtn").on("click", function(event) {
		event.preventDefault();

		// 获取联系表单输入值
		var name = jQuery("#login_name").val().trim();
		var pwd = jQuery("#login_pwd").val().trim();
		var pwd_ch = jQuery("#login_pwd_ch").val().trim();
		var phone = jQuery("#phone").val().trim();

		var phone_code = jQuery("#phone_code").val().trim();
			
		var ap_plokicy_r = jQuery("#ap_plokicy_r").val().trim();

		// 检查空字段
		if (name === '') {
			jQuery('div.empty-name').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查空字段
		if (pwd === '') {
			jQuery('div.empty-pwd').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查字段相同
		if (pwd != pwd_ch) {
			jQuery('div.empty-error').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 检查勾选
		if (ap_plokicy_r === '0') {
			jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
			return;
		}
		// 信息得到验证 - 发送注册表单
		var url = "/reg_do";
		var urlData = {
				login_name: name, 
				password: pwd,
				phone: phone,
				phone_code: phone_code,
			};
		
        jQuery.post(url, urlData,
			function (data) {
	            if (data.status) {
	            	// 注册成功
	            	if (data.type == 0) {
		                window.location.replace(data.url);
	            		
	            	} else if (data.type == 3) {// 手机验证码错误
		            	 jQuery('div.empty-phone').slideDown(500).delay(2000).slideUp(500);
	            	}
	                 
	             } else {
	            	 // 注册失败
	            	 if (data.type == 1) {// 帐号重复
		            	 jQuery('div.empty-invalid').slideDown(500).delay(2000).slideUp(500);
		            	 
	            	 } else if (data.type == 2) {
	            		 // 其他错误
	            	 }
	            	 
	             }
	        }, "json"
		);
	});
}

/*请同意我们的隐私权保护条款*/
function appinocks_privacy_plokicy() {
	"use-strict";
	
	//隐藏text block，显示password block
	jQuery("#ap_plokicy").on("click", function(event) {
		event.preventDefault();
		let type = jQuery("#ap_plokicy").attr('class');
		if(type === "fa fa-close fa-lg"){
			jQuery("#ap_plokicy").attr("class","fa fa-check fa-lg");
			jQuery("#ap_plokicy_r").attr("value","1");
			
		}else{
			jQuery("#ap_plokicy").attr("class","fa fa-close fa-lg");
			jQuery("#ap_plokicy_r").attr("value","0");
		}
	});
}

/**用户资料修改*/
function appinocks_userEdit() {
	"use-strict";

	jQuery("#user_editBtn").on("click", function(event) {
		event.preventDefault();
		
		// 获取联系表单输入值
		var id = jQuery("#id").val().trim();
		var login_name = jQuery("#login_name").val().trim();
		
		var name = jQuery("#name").val().trim();
		var yyyymmdd = jQuery("#yyyymmdd").val().trim();
			
		var hospital_id = jQuery("#hospital_id").val().trim();
		var post_no = jQuery("#post_no").val().trim();

		var password = jQuery("#password").val().trim();
		var new_password = jQuery("#new_password").val().trim();
			
		var types = jQuery("#types").val().trim();
		var lic = jQuery("#lic").val().trim();
		
		var phone = jQuery("#phone").val().trim();
		var phone_code = jQuery("#phone_code").val().trim();
			
		var wechat = jQuery("#wechat").val().trim();
		var qq = jQuery("#qq").val().trim();
			
		var mail = jQuery("#mail").val().trim();
		var mail_code = jQuery("#mail_code").val().trim();
			
		var address = jQuery("#address").val().trim();
		var play_sound = jQuery('input:radio[name=play_sound]:checked').val();
		
		// 检查空字段 - 姓名
		if (name === '') {
			jQuery('div.empty-name').slideDown(500).delay(2000).slideUp(500);
			return;
		}

		// 检查空字段 - 密码
		if (password === '') {
			jQuery('div.empty-pwd').slideDown(500).delay(2000).slideUp(500);
			return;
		}

		// 信息得到验证 - 发送修改表单
		var url = "/user_edit_do";
		var urlData = {
				id: id,
				login_name: login_name, 
				name: name, 
				yyyymmdd: yyyymmdd,
				
				hospital_id: hospital_id,
				post_no: post_no,
				
				password: password, 
				new_password: new_password, 
				
				type: types,
				license: lic,
				
				phone: phone, 
				phone_code: phone_code, 
				
				wechat: wechat, 
				qq: qq, 
				
				mail: mail, 
				mail_code: mail_code, 
				
				address: address,
				play_sound: play_sound
			};
		
        jQuery.post(url, urlData,
			function (data) {
	            if (data.status) {
	            	if (data.mode == 0) {
		            	// 修改成功
		            	window.location.replace(data.url);
	            		
	            	} else if (data.mode == 1) {
	            		// 密码错误
	    				jQuery('div.empty-error').slideDown(500).delay(2000).slideUp(500);
	            		
	            	} else if (data.mode == 2) {
	            		// 密码修改
		            	window.location.replace(data.url);
	            		
	            	} else if (data.mode == 3) {
	            		// 手机验证码错误
	    				jQuery('div.empty-phone').slideDown(500).delay(2000).slideUp(500);
	            		
	            	} else if (data.mode == 4) {
	            		// 邮件验证码错误
	    				jQuery('div.empty-mail').slideDown(500).delay(2000).slideUp(500);
	            		
	            	} else if (data.mode == 5) {
	            		// 手机号码已经使用
		            	 jQuery('div.empty-msg').slideDown(500).delay(2000).slideUp(500);
	            	}
	                 
	             } else {
	            	 // 修改失败
	            	 window.location.replace(data.url);
	             }
	        }, "json"
		);
	});
}

/*  -----------------------------------------------------
    9.加载器
    ----------------------------------------------------- */
function appinocks_preloader() {
	"use-strict";

	// Variables
	var preloaderWrap = jQuery('.preloader-wrap'),
		loaderInner = jQuery('.preloader-wrap .preloader-inner');

	jQuery(window).load('body', function() {
		loaderInner.fadeOut();
		preloaderWrap.delay(350).fadeOut('slow');
	});
}

/*  -----------------------------------------------------
    10.ScrollIt
    ----------------------------------------------------- */
function appinocks_scrollIt() {
	"use-strict";

	jQuery.scrollIt({
		upKey: 38,
		downKey: 40,
		easing: "swing",
		scrollTime: 600,
		activeClass: "active",
		onPageChange: null,
		topOffset: -15
	});
}

/*  -----------------------------------------------------
    11.向上滚动卷轴
    ----------------------------------------------------- */
function appinocks_scrollUp() {
	"use-strict";

	jQuery('.scroll-top-btn').on("click", function(event) {

		event.preventDefault();

		jQuery('html, body').animate({
			scrollTop: jQuery(jQuery.attr(this, 'href')).offset().top
		}, 500);

	});
}

appinocks_scrollUp();

